package com.wk.paradise.main.controller;

import com.wk.paradise.main.bean.pojo.Menu;
import com.wk.paradise.main.bean.pojo.ResultPojo;
import com.wk.paradise.main.service.MenuService;
import java.util.List;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author weikai
 * @description
 * @date 2019/12/26
 */
@Controller
@RequestMapping()
public class IndexController {

  @Value("${head.msg}")
  private String msg;

  private final String MSG = "再牛逼的梦想，也经不起你傻逼似的坚持！";

  Logger logger = LoggerFactory.getLogger(IndexController.class);

  @Autowired
  private MenuService menuService;

  /**
   * @return
   */
  @RequestMapping("/pages")
  @ResponseBody
  public Object menuList() {
    List<Menu> list = null;
    try {
      list = menuService.getMenu();
      return ResultPojo.OK_RESULT(list);
    } catch (Exception e) {
      logger.info("获取导航栏页面失败:{}", e.getMessage());
      return ResultPojo.ERROR_RESULT(list);
    }
  }

  @RequestMapping("/head")
  @ResponseBody
  public Object head() {

    if(StringUtils.isEmpty(msg) || StringUtils.equals(msg,"${head.msg}")){
      msg = MSG;
    }
    return ResultPojo.OK_RESULT(msg);
  }
}
